package com.xbongbong.paas.domain.entity.ext;

import com.alibaba.fastjson.JSONArray;
import com.xbongbong.paas.domain.entity.PaasProcessTemplateNodeEntity;
import com.xbongbong.paas.toolbox.util.DateTimeUtil;
import lombok.Getter;
import lombok.ToString;

import java.util.List;
import java.util.Map;

/**
 * @author: wufeng
 * @date: 2018/8/20 15:42
 * @desrcption:
 */
@Getter
@ToString
public class PaasProcessTemplateNodeEntityExt extends PaasProcessTemplateNodeEntity {

    private static final long serialVersionUID = -4529094870773237799L;

    /**
     * 负责人list TODO 手动拼装
     */
    private List<OptionalRangeEntity> mainUserList;

    /**
     * 抄送人list TODO 手动拼装
     */
    private List<OptionalRangeEntity> ccUserList;

    /**
     * 转交人list TODO 手动拼装
     */
    private List<OptionalRangeEntity> transferUserList;

    /**
     * 打回节点list
     */
    private List<Long> backNodeList;

    /**
     * 字段权限
     */
    private List<FieldPermissionEntityExt> fieldPermissionList;

    private Map<String, FieldPermissionEntityExt> fieldPermissionMap;
    /**
     * 节点校验条件列表
     */
    private List<CommitVerifyConditionEntityExt> commitVerifyConditionList;
    /**
     * 解析后的流转条件
     */
    private List<ConditionsEntityExt> conditions;

    /**
     * 表单数据id
     */
    private Long formDataId;

    public PaasProcessTemplateNodeEntityExt(){}

    public PaasProcessTemplateNodeEntityExt (boolean initFlag, String corpid, Long appId, Long menuId, Long formId, Long templateId) {
        this.setCorpid(corpid);
        this.setAppId(appId);
        this.setMenuId(menuId);
        this.setFormId(formId);
        this.setTemplateId(templateId);
        long now = DateTimeUtil.getInt();
        if (initFlag) {
            this.setEnableCCFlag(0);
            this.setCcUser("[]");
            this.setOpinionFlag(0);
            this.setEnable(1);
            this.setCommitFlag(1);
            this.setCommitText("同意");
            this.setStorageFlag(1);
            this.setStorageText("暂存");
            this.setCommitPrintFlag(0);
            this.setCommitPrintText("提交并打印");
            this.setBackFlag(0);
            this.setBackType(0);
            this.setBackText("回退");
            this.setBackNode("[]");
            this.setTransferFlag(0);
            this.setTransferText("转交");
            this.setTransferUser("[]");
            this.setEndFlag(1);
            this.setEndText("拒绝");
            this.setCommitVerifyFlag(1);
            this.setCommitVerifyCondition("[]");
            this.setSignType(1);
            this.setPrintTemplateId(0L);
            this.setCcPrintFlag(0);
            this.setX(0D);
            this.setY(0D);
            this.setAddTime(now);
            this.setDel(0);
        }
        this.setUpdateTime(now);
    }

    public void setMainUserList(String mainUser) {
        this.mainUserList = JSONArray.parseArray(mainUser, OptionalRangeEntity.class);
    }

    public void setCcUserList(String ccUser) {
        this.ccUserList = JSONArray.parseArray(ccUser, OptionalRangeEntity.class);
    }

    public void setTransferUserList(String transferUser) {
        this.transferUserList = JSONArray.parseArray(transferUser, OptionalRangeEntity.class);
    }

    public void setBackNodeList(String backNodeList) {
        this.backNodeList = JSONArray.parseArray(backNodeList, Long.class);
    }

    public void setFieldPermissionList(String fieldPermission) {
        this.fieldPermissionList = JSONArray.parseArray(fieldPermission, FieldPermissionEntityExt.class);
    }

    public void setCommitVerifyConditionList(String commitVerifyCondition) {
        this.commitVerifyConditionList = JSONArray.parseArray(commitVerifyCondition, CommitVerifyConditionEntityExt.class);
    }

    public void setFormDataId(Long formDataId) {
        this.formDataId = formDataId;
    }

    public void setConditions(String condition) {
        this.conditions = JSONArray.parseArray(condition, ConditionsEntityExt.class);
    }

    public void setConditionByClass(List<ConditionsEntityExt> conditionList){
        this.conditions = conditionList;
    }

    public void setFieldPermissionMap(Map<String, FieldPermissionEntityExt> fieldPermissionMap) {
        this.fieldPermissionMap = fieldPermissionMap;
    }
}
